﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.IO;

namespace GraphicLib
{
    public class BitmapGetter
    {
        /// <summary>
        /// 得到图像列表
        /// </summary>
        /// <returns></returns>
        public static List<Bitmap> GetBitmaps(string dirPath)
        {
            List<Bitmap> bitmaps = new List<Bitmap>();
            string[] files = Directory.GetFiles(dirPath);
            foreach (string file in files)
            {
                try
                {
                    Bitmap bitmap = (Bitmap)Image.FromFile(file);
                    bitmaps.Add(bitmap);
                }
                catch (Exception ex)
                {
                    File.AppendAllText(Sample.LOG_PATH, ex.Message);
                }
            }
            return bitmaps;
        }

        /// <summary>
        /// 得到样本图像列表
        /// </summary>
        /// <returns></returns>
        public static List<Bitmap> GetSampleBitmaps()
        {
            return GetBitmaps(Sample.NEW_SAMPLE_DIR);
        }

        /// <summary>
        /// 得到初始化过的样本图像列表
        /// </summary>
        /// <returns></returns>
        public static List<Bitmap> GetInitializedBitmaps()
        {
            return GetBitmaps(Sample.INITIALIZED_SAMPLE_DIR);
        }

        /// <summary>
        /// 得到产品图像列表
        /// </summary>
        /// <returns></returns>
        public static Dictionary<string, Bitmap> GetProductBitmaps()
        {
            return GetSingleBitmapAndOriFileName(Sample.PRODUCT_DIR);
        }


        public static Dictionary<string, Bitmap> GetSingleBitmapAndOriFileName(string dirPath)
        {

            Dictionary<string, Bitmap> bitmaps = new Dictionary<string, Bitmap>();
            string[] files = Directory.GetFiles(dirPath);
            foreach (string file in files)
            {
                try
                {
                    Bitmap bitmap = (Bitmap)Image.FromFile(file);
                    bitmaps.Add(file, bitmap);
                    return bitmaps;
                }
                catch (Exception ex)
                {
                    File.AppendAllText(Sample.LOG_PATH, ex.Message);
                }
            }
            return bitmaps;
        }

        public static Dictionary<string, Bitmap> GetBitmapsAndOriFileName(string dirPath)
        {

            Dictionary<string, Bitmap> bitmaps = new Dictionary<string, Bitmap>();
            string[] files = Directory.GetFiles(dirPath);
            foreach (string file in files)
            {
                try
                {
                    Bitmap bitmap = (Bitmap)Image.FromFile(file);
                    bitmaps.Add(file, bitmap);
                }
                catch (Exception ex)
                {
                    File.AppendAllText(Sample.LOG_PATH, ex.Message);
                }
            }
            return bitmaps;
        }
    }
}
